package LC;

import static Studing.Sort.swap;

/**
 * @ClassName LC31
 * @Description: TODO
 * @Author hl
 * @Date 2021/4/15
 * @Version V1.0
 **/
public class LC31 {
    public static void nextPermutation(int[] nums) {
        int i=nums.length-2;
        while(i>=0&&nums[i]>=nums[i+1]){
            i--;
        }
        int j=nums.length-1;
        if(i>=0){
            while(i>=0&&nums[i]>=nums[j]){
                j--;
            }
            swap(nums,i,j);//交换i与j
        }
        reSort(nums,i);//
    }

    private static void reSort(int[] nums, int i) {
        int start=i+1;
        int end=nums.length-1;
        while(start<end){
            swap(nums,start,end);
            start++;
            end--;
        }
    }
    public  static  void swap(int []arr,int i,int j){
        int temp=arr[i];
        arr[i]=arr[j];
        arr[j]=temp;
    }


    public static void main(String[] args) {
        int []nums={2,1};
        nextPermutation(nums);

    }
}
